/**
 * Project Name:mauto-web
 * File Name:AreaService.java
 * Package Name:com.inftech.mauto.sys.service
 * Date:2016年10月7日下午9:14:13
 * Copyright (c) 2016, inf-technology Co., Ltd. All Rights Reserved.
 *
*/

package com.inftech.mauto.sys.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.inftech.mauto.sys.dao.IDictDao;
import com.inftech.mauto.sys.entity.Dict;
import com.mingsoft.base.biz.impl.BaseBizImpl;
import com.mingsoft.base.dao.IBaseDao;

/**
 * ClassName:DictService <br/>
 * Function: 数据字典业务service. <br/>
 * Date: 2016年10月7日 下午9:14:13 <br/>
 * 
 * @author puyf
 * @version
 * @since JDK 1.7
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Service("dictService")
public class DictService extends BaseBizImpl {

	/**
	 * 数据字典持久化层注入
	 */
	@Autowired
	private IDictDao dictDao;

	@Override
	protected IBaseDao getDao() {
		return dictDao;
	}

	/**
	 * 
	 * queryDictListFront:获取字典项. <br/>
	 *
	 * @author puyf
	 * @param parentKey
	 * @return
	 * @throws Exception
	 * @since JDK 1.7
	 */
	public List<Map<String, Object>> queryDictListFront(String parentKey) throws Exception {
		List<Dict> dictList = dictDao.queryDictList(parentKey);
		// 返回对象
		List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
		if (dictList != null && dictList.size() != 0) {
			for (Dict dict : dictList) {
				Map<String, Object> dictMap = new HashMap<String, Object>();
				dictMap.put("value", dict.getDictKey());
				dictMap.put("text", dict.getDictValue());
				resultList.add(dictMap);
			}
		}
		return resultList;
	}

	/**
	 * 
	 * queryDictList:后台获取字典项. <br/>
	 *
	 * @author puyf
	 * @param parentKey
	 * @return
	 * @since JDK 1.7
	 */
	public List<Map.Entry<String, String>> queryDictList(String parentKey) throws Exception {
		List<Dict> dictList = dictDao.queryDictList(parentKey);
		Map<String, String> map = new LinkedHashMap<String, String>();
		if (dictList != null && dictList.size() != 0) {
			for (Dict dict : dictList) {
				map.put(dict.getDictKey(), dict.getDictValue());
			}
		}
		Set<Entry<String, String>> set = map.entrySet();
		List<Map.Entry<String, String>> resultList = new ArrayList<Map.Entry<String, String>>();
		for (Iterator<Entry<String, String>> it = set.iterator(); it.hasNext();) {
			Map.Entry<String, String> entry = (Map.Entry<String, String>) it.next();
			resultList.add(entry);
		}
		return resultList;
	}

}
